<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">deferred.catch()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/deferred-object/">延迟对象</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/deferred.catch/" target="_blank">deferred.catch()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<article class="entry method" id="deferred-catch1"><h2 class="section-title">
<span class="name">deferred.catch( failFilter )</span><span class="returns">Returns: <a href="http://api.jquery.com/Types/#Promise">Promise</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>Description: </strong>Add handlers to be called when the Deferred object is rejected. </p>
<ul class="signatures"><li class="signature">
<h4 class="name">
<span class="version-details">version added: <a href="/category/version/3.0/">3.0</a></span><a href="#deferred-catch-failFilter" id="deferred-catch-failFilter"><span class="icon-link"></span>deferred.catch( failFilter )</a>
</h4>
<ul><li>
<div><strong>failFilter</strong></div>
<div>Type: <a href="http://api.jquery.com/Types/#Function">Function</a>()</div>
<div>
			                A function that is called when the Deferred is rejected.
			            </div>
</li></ul>
</li></ul>
<div class="longdesc" id="entry-longdesc">
<p><code>deferred.catch( fn )</code> is an alias to <a href="/deferred.then/"><code>deferred.then( null, fn )</code></a>. Read its page for more information.</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2>Example:</h2></header><div class="entry-example" id="example-0">
<p>Since the <a href="/jQuery.get/"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred object, we can rejection handlers using the <code>.catch</code> method.</p>
<div class="syntaxhighlighter javascript">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$.get( <span class="string">"test.php"</span> )</code></div></div><div class="container"><div class="line"><code>  .then( <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code>    alert( <span class="string">"$.get succeeded"</span> );</code></div></div><div class="container"><div class="line"><code>  } )</code></div></div><div class="container"><div class="line"><code>  .<span class="keyword">catch</span>( <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code>    alert( <span class="string">"$.get failed!"</span> );</code></div></div><div class="container"><div class="line"><code>  } );</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article>
</article>